﻿@namespace BlazorFluentUI
@inherits FluentUIComponentBase

<div>
    <ResizeGroup OnGrowData=@onGrowData OnReduceData=@onReduceData
                    Data=@_currentData
                    GetCacheKey=@(x => x!.CacheKey)
                    ClassName=@ClassName
                    Style=@Style>
        <DataTemplate Context="data">
            <div class="mediumFont ms-CommandBar" role="menubar">
                @*Primary*@
                <OverflowSet ClassName="ms-CommandBar-primarySet" Items=@data!.PrimaryItems OverflowItems=@(data.OverflowItems!.Count() > 0 ? data.OverflowItems : null) GetKey=@(x=>x.Key)>
                    <ItemTemplate>
                        @if (ItemTemplate != null)
                        {
                            @ItemTemplate(context)
                        }
                        else
                        {
                            @if (context.IconOnly)
                            {
                                <TooltipHost>
                                    <ChildContent>
                                        <CommandBarButton IconName=@context.IconName
                                                             IconSrc="@context.IconSrc"
                                                             Text=@(!context.IconOnly ? context.Text : null)
                                                             MenuItems=@context.Items
                                                             Href=@context.Href
                                                             OnClick=@(args => context.OnClick?.Invoke(new ItemClickedArgs() { MouseEventArgs = args, Key = context.Key }))
                                                             Command=@context.Command CommandParameter=@context.CommandParameter
                                                             Disabled=@context.Disabled AriaLabel=@context.AriaLabel Checked=@context.Checked ClassName=@context.ClassName
                                                             Split=@context.Split Style=@context.Style
                                                             Toggle=@context.Toggle
                                                             IsRadioButton=@context.IsRadioButton GroupName=@context.GroupName />
                                    </ChildContent>
                                    <TooltipContent>
                                        @context.Text
                                    </TooltipContent>
                                </TooltipHost>
                            }
                            else
                            {
                                <CommandBarButton IconName=@context.IconName
                                                     IconSrc="@context.IconSrc"
                                                     Text=@(!context.IconOnly ? context.Text : null)
                                                     MenuItems=@context.Items
                                                     Href=@context.Href
                                                     OnClick=@(args => context.OnClick?.Invoke(new ItemClickedArgs() { MouseEventArgs = args, Key = context.Key }))
                                                     Command=@context.Command CommandParameter=@context.CommandParameter
                                                     Disabled=@context.Disabled AriaLabel=@context.AriaLabel Checked=@context.Checked ClassName=@context.ClassName
                                                     Split=@context.Split Style=@context.Style
                                                     Toggle=@context.Toggle
                                                     IsRadioButton=@context.IsRadioButton GroupName=@context.GroupName/>
                            }
                        }
                    </ItemTemplate>
                    <OverflowTemplate>
                        <CommandBarButton HideChevron="true" Style="min-width: 0; padding: 0 4px; align-self: stretch;" IconName="more_horizontal" MenuItems=@context />
                    </OverflowTemplate>

                </OverflowSet>
                @*Secondary*@
                <OverflowSet ClassName="ms-CommandBar-secondarySet" Items=@data.FarItems GetKey=@(x=>x.Key)>
                    <ItemTemplate>
                        @if (context.IconOnly)
                        {
                            <TooltipHost>
                                <ChildContent>
                                    <CommandBarButton IconName=@context.IconName
                                                         IconSrc="@context.IconSrc"
                                                         Text=@(!context.IconOnly ? context.Text : null)
                                                         MenuItems=@context.Items
                                                         Href=@context.Href
                                                         OnClick=@(args => context.OnClick?.Invoke(new ItemClickedArgs() { MouseEventArgs = args, Key = context.Key }))
                                                         Command=@context.Command CommandParameter=@context.CommandParameter
                                                         Disabled=@context.Disabled AriaLabel=@context.AriaLabel Checked=@context.Checked ClassName=@context.ClassName
                                                         Split=@context.Split Style=@context.Style
                                                         Toggle=@context.Toggle
                                                         IsRadioButton=@context.IsRadioButton GroupName=@context.GroupName/>
                                </ChildContent>
                                <TooltipContent>
                                    @context.Text
                                </TooltipContent>
                            </TooltipHost>
                        }
                        else
                        {
                            <CommandBarButton IconName=@context.IconName
                                                 IconSrc=@context.IconSrc
                                                 Text=@(!context.IconOnly ? context.Text : null)
                                                 Href=@context.Href
                                                 MenuItems=@context.Items
                                                 OnClick=@(args => context.OnClick?.Invoke(new ItemClickedArgs() { MouseEventArgs = args, Key = context.Key }))
                                                 Command=@context.Command CommandParameter=@context.CommandParameter
                                                 Disabled=@context.Disabled AriaLabel=@context.AriaLabel Checked=@context.Checked ClassName=@context.ClassName
                                                 Split=@context.Split Style=@context.Style
                                                 Toggle=@context.Toggle
                                                 IsRadioButton=@context.IsRadioButton GroupName=@context.GroupName/>
                        }
                    </ItemTemplate>

                </OverflowSet>
            </div>
        </DataTemplate>
    </ResizeGroup>
</div>